#include <stdio.h>
int judge(int year)
{
	if(year%400==0||(year%4==0&&year%100!=0))
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
int main()
{
	int year,day;
	scanf("%d %d",&year,&day);
	int month[12]={31, 28 + judge(year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	int outmonth=0;
	int outday=day;
	while(outday-month[outmonth]>0)
	{
		outday-=month[outmonth];
		outmonth++;
	}
	printf("%d %d",outmonth+1,outday);
	return 0;
}
	
